package arithmetic;

import java.util.Scanner;

/**
 * 数字游戏，逢3退出，剩余的最后一个人为胜利者
 */
public class SuanFa_02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        boolean[] members = new boolean[n];
        int len = members.length;
        int num = 0;
        int index = 0;

        while (len > 1) {
            if (!members[index]) {
                num++;
                if (num == 3) {
                    num = 0;
                    members[index] = true;
                    len--;
                }
            }
            index++;
            if (index >= members.length) {
                index = 0;
            }
        }

        for (int i = 0; i < members.length; i++) {
            if (!members[i]) {
                System.out.println(i + 1);
            }
        }
    }
}
